import 'package:flutter_base_app/model/login_data.dart';
import 'package:flutter_base_app/model/test_data.dart';
import 'package:flutter_http_utils/flutter_http_utils.dart';

import '../utils/http/http_ui_handle.dart';
import '../utils/user/user_data.dart';

class ApiMain {
  ApiMain._();

  ///推荐
  static Future<HttpResult<List<TestData>>> recommend(HttpUiHandler? handler) async =>
      await HttpUtils.request(
        parser: HttpResult<List<TestData>>.asT,
        handler: handler,
        queryParameters: {"action": "recommend"},
      );

  //登录
  static Future<HttpResult<LoginData>> login(
    String userName,
    String password,
    HttpUiHandler? handler,
  ) =>
      HttpUtils.request(
        parser: HttpResult<LoginData>.asT,
        handler: handler,
        path: "/user/login",
        data: {"userName": userName, "password": password},
      );

  /// 查询用户信息(My Profile页面)
  static Future<HttpResult<UserInfoData>> userInfo([HttpUiHandler? handler]) => HttpUtils.get(
        parser: HttpResult<UserInfoData>.asT,
        handler: handler,
        path: "/user/info",
      );
}
